﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Gonte.Validation
{
    public class ValidationException
        : Exception
    {
        #region Constructors

        public ValidationException(List<ValidationError> errors)
            : base(BuildMessageFromErrors(errors))
        {
        }

        #endregion

        private static string BuildMessageFromErrors(List<ValidationError> errors)
        {
            StringBuilder errorbuilder = new StringBuilder();
            errorbuilder.Append("One or more validation errors have occurred:");

            foreach (ValidationError error in errors)
            {
                errorbuilder.Append(Environment.NewLine);
                errorbuilder.Append(error.ToString());
            }

            return errorbuilder.ToString();
        }
    }
}
